<?php
class picture_special_row extends system_concept_row {
	
	protected $_cover = null;
	/**
	 * @return resource_display
	 */
	public function getCover() {
		if($this->_cover === null) {
			$this->_cover = new resource_display($this->get('cover'));
		}
		return $this->_cover;
	}
	
	public function setName($name) {
		if(!$name) {
			$this->set('name', '');
		} else {
			$name = preg_replace('#[\\\\\\\/\?\|\#]+#isU', '-', $name);
			$this->set('name', $name);
		}
		return $this;
	}
	
	protected $_categoryList = array();
	public function addCategoryList($id) {
		$this->_categoryList[$id] = $id;
	}
	public function getCategoryList() {
		return $this->_categoryList;
	}
	
	protected $_keyword = array();
	/**
	 * @return picture_special_row
	 */
	public function setKeywords($keyword) {
		if(!$keyword) return $this;
		if(!is_array($keyword)) {
			$keyword = explode(';', trim((string)$keyword));
		}
		$k = array();
		foreach($keyword AS $key) {
			$key = trim($key);
			if($key == '') continue;
			$k[] = $key;		}
		
		$this->_keyword = $k;
		return $this;
	}
	public function getKeywords() {
		$list = array();
		if($this->getId()) {
			$concept = new resource_keyword_concept();
			foreach($concept->fetchAll(array('id IN (SELECT `keyword_id` FROM `picture_special_keyword` WHERE `special_id` = ?)' => $this->getId())) AS $row) {
				$list[] = $row->getName();
			}
		}
		return array_merge($this->_keyword, $list);
	}
	
	public function updatePhotoCount() {
		$concept = new picture_special_photo_concept();
		$count = $concept->fetchCount(array('special_id = ?' => $this->getId()));
		$this->setPtotal($count);
		$this->update();
	}
		
}
